package com.zs4sdk.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;

import com.zs4sdk.Zs4GameBase;
import com.zs4sdk.common.Extra;
import com.zs4sdk.extra.Zs4GameCode;
import com.common.library.util.ActivityHelper;
import com.common.library.util.Helper;
import com.common.library.util.NetworkHelper;

/**
 * 
 * function: 公告页面
 * 
 * @ author: aXiBa
 */
public class Zs4GameNoticeActivity extends Zs4GameBaseWebActivity {
	
	public static final String TAG = Zs4GameNoticeActivity.class.getSimpleName();
	
	ImageButton mCloseView;
	TextView mTitleView;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(ActivityHelper.getLayoutResId("zs4gamelayout_view_notice"));
		
		
		init();
	}
	
	
	protected void init() {
		
		//初始化WebView
		this.mWebView = findView(WebView.class, "zs4gameviewid_web_container");
		if (Helper.isNotNull(this.mWebView)){
			this.mWebView.requestFocus();
            this.mWebView.getSettings().setUseWideViewPort(true);
            this.mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
			this.mWebView.getSettings().setSupportZoom(false);
			this.mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
			this.mWebView.getSettings().setBuiltInZoomControls(false);
			this.mWebView.setWebViewClient(this.createWebViewClient());
			this.mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
		}

		this.mWebView.setWebChromeClient(wvcc);

		initReferences();
		
		//未接网络提示
		if(!NetworkHelper.isNetworkAvailable(this)){
			ActivityHelper.showToast(ActivityHelper.getStringResId("zs4gamestring_hint_has_not_network"));
		}
		else {
			getWebView().loadUrl(Extra.URL.NOTICEURL, getHeader());
		}
		
		// 点击关闭，发INITCOMPLETE消息
		mCloseView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				ActivityHelper.sendBroadcast(Zs4GameBase.getPackageName().concat(Extra.ACTIONKEY.INIT_POSTFIX), Zs4GameCode.INITCOMPLETE, Zs4GameNoticeActivity.this);
				Zs4GameNoticeActivity.this.finish();
			}
		});
		
	}



	@Override
	protected WebViewClient createWebViewClient() {
		
		WebViewClient webViewClient = new WebViewClient() {

			// 里面的url点击可跳转到浏览器
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				Uri uri = Uri.parse(url); 
	            Intent intent =new Intent(Intent.ACTION_VIEW, uri);  
	            Zs4GameNoticeActivity.this.startActivity(intent);
	            return true;
			}
			
		};
		return webViewClient;
	}
	
	
	WebChromeClient wvcc = new WebChromeClient() {  
        @Override  
        public void onReceivedTitle(WebView view, String title) {  
            super.onReceivedTitle(view, title);  
            // 读取webview title
            mTitleView.setText(title);
			return;
        }  

    };

	private void initReferences() {
		
		mCloseView = (ImageButton) findViewById(ActivityHelper.getIdResId("zs4gameviewid_mCloseView_view_notice"));
		mTitleView = (TextView) findViewById(ActivityHelper.getIdResId("zs4gameviewid_mTitleView_view_notice"));
		
	}
	

	// 不能后退
	@Override
	public void onBackPressed() {
		
	}
}
